package com.wisdomparking.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wisdomparking.bean.User;
import com.wisdomparking.dao.UserDao;
import com.wisdomparking.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired UserDao userDao;
	
	// 添加
	@Override
	public boolean addUser(User en, boolean sign) {
		int i = 0;
		
		try {

			if (sign) {
				i = userDao.insert(en);
			} else {
				i = userDao.insertSelective(en);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		return i == 1 ? true : false;
	}
	
	// 修改
	@Override
	public boolean updateUser(User en, boolean sign) {
		int i = 0;

		try {

			if (sign) {
				i = userDao.updateByPrimaryKey(en);
			} else {
				i = userDao.updateByPrimaryKeySelective(en);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return i == 1 ? true : false;
	}
	
	// 删除
	@Override
	public boolean deleteUserById(Integer id) {
		
		return userDao.deleteByPrimaryKey(id)==1?true:false;
	}
	
	// 查询
	@Override
	public User getUser(Integer id) {
		
		return userDao.selectByPrimaryKey(id);
	}
	
	// 查询
	@Override
	public User getUserByMobileNumber(String mobileNumber){
		
		return userDao.selectByMobileNumber(mobileNumber);
	}
	
	// 查询
	@Override
	public User getUserByTempMobile(String tempMobile){
		
		return userDao.selectByTempMobile(tempMobile);
	}
	
	// 获取对象列表
	@Override
	public List<User> getUserList(Map<String, Object> map) {
		
		return userDao.getUserList(map);
	}
	
	// 获取记录总条数
	@Override
	public long getCountByUser(Map<String, Object> map){
		
		return userDao.getCountByUser(map);
	}
	
}
